home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / mpeg_play-2.1 / floatdct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-09  |  3.0 KB  |  123 lines

  1. /* idctref.c, Inverse Discrete Fourier Transform, double precision          */
  2.  
  3. /* Copyright (C) 1994, MPEG Software Simulation Group. All Rights Reserved. */
  4.  
  5. /*
  6.  * Disclaimer of Warranty
  7.  *
  8.  * These software programs are available to the user without any license fee or
  9.  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
  10.  * any and all warranties, whether express, implied, or statuary, including any
  11.  * implied warranties or merchantability or of fitness for a particular
  12.  * purpose.  In no event shall the copyright-holder be liable for any
  13.  * incidental, punitive, or consequential damages of any kind whatsoever
  14.  * arising from the use of these programs.
  15.  *
  16.  * This disclaimer of warranty extends to the user of these programs and user's
  17.  * customers, employees, agents, transferees, successors, and assigns.
  18.  *
  19.  * The MPEG Software Simulation Group does not represent or warrant that the
  20.  * programs furnished hereunder are free of infringement of any third-party
  21.  * patents.
  22.  *
  23.  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
  24.  * are subject to royalty fees to patent holders.  Many of these patents are
  25.  * general enough such that they are unavoidable regardless of implementation
  26.  * design.
  27.  *
  28.  */
  29.  
  30. /*  Perform IEEE 1180 reference (64-bit floating point, separable 8x1
  31.  *  direct matrix multiply) Inverse Discrete Cosine Transform
  32. */
  33.  
  34.  
  35. /* Here we use math.h to generate constants.  Compiler results may
  36.    vary a little */
  37.  
  38. #include <math.h>
  39.  
  40. /* define NON_ANSI_COMPILER for compilers without function prototyping */
  41. /* #define NON_ANSI_COMPILER */
  42.  
  43. #ifdef NON_ANSI_COMPILER
  44. #define _ANSI_ARGS_(x) ()
  45. #else
  46. #define _ANSI_ARGS_(x) x
  47. #endif
  48.  
  49. #define RB "rb"
  50. #define WB "wb"
  51.  
  52. #ifndef O_BINARY
  53. #define O_BINARY 0
  54. #endif
  55.  
  56. #ifndef PI
  57. # ifdef M_PI
  58. #  define PI M_PI
  59. # else
  60. #  define PI 3.14159265358979323846
  61. # endif
  62. #endif
  63.  
  64. /* global declarations */
  65. void init_float_idct _ANSI_ARGS_((void));
  66. void float_idct _ANSI_ARGS_((short *block));
  67.  
  68. /* private data */
  69.  
  70. /* cosine transform matrix for 8x1 IDCT */
  71. static double c[8][8];
  72.  
  73. /* initialize DCT coefficient matrix */
  74.  
  75. void init_float_idct()
  76. {
  77.   int freq, time;
  78.   double scale;
  79.  
  80.   for (freq=0; freq < 8; freq++)
  81.   {
  82.     scale = (freq == 0) ? sqrt(0.125) : 0.5;
  83.     for (time=0; time<8; time++)
  84.       c[freq][time] = scale*cos((PI/8.0)*freq*(time + 0.5));
  85.   }
  86. }
  87.  
  88. /* perform IDCT matrix multiply for 8x8 coefficient block */
  89.  
  90. void float_idct(block)
  91. short *block;
  92. {
  93.   int i, j, k, v;
  94.   double partial_product;
  95.   double tmp[64];
  96.  
  97.   for (i=0; i<8; i++)
  98.     for (j=0; j<8; j++)
  99.     {
  100.       partial_product = 0.0;
  101.  
  102.       for (k=0; k<8; k++)
  103.         partial_product+= c[k][j]*block[8*i+k];
  104.  
  105.       tmp[8*i+j] = partial_product;
  106.     }
  107.  
  108.   /* Transpose operation is integrated into address mapping by switching 
  109.      loop order of i and j */
  110.  
  111.   for (j=0; j<8; j++)
  112.     for (i=0; i<8; i++)
  113.     {
  114.       partial_product = 0.0;
  115.  
  116.       for (k=0; k<8; k++)
  117.         partial_product+= c[k][i]*tmp[8*k+j];
  118.  
  119.       v = floor(partial_product+0.5);
  120.       block[8*i+j] = (v<-256) ? -256 : ((v>255) ? 255 : v);
  121.     }
  122. }
  123.